package com.liqi.web.controller.openapi.middleware;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.liqi.common.core.controller.BaseController;
import com.liqi.common.core.domain.AjaxResult;
import com.liqi.common.core.domain.R;
import com.liqi.common.utils.StringUtils;
import com.liqi.deployment.domain.DvDeployment;
import com.liqi.deployment.service.IDvDeploymentService;
import com.liqi.monitor.domain.DvDeploymentSystem;
import com.liqi.monitor.dto.ShutdownStatusDto;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 接受客户端关机信息接口
 *
 */
@Api(tags = "提供给中间件的接口")
@RestController
@RequestMapping("/openApi/middleware")
public class ShutdownStatusController extends BaseController{
    @Autowired
    private IDvDeploymentService dvDeploymentService;
    
	/**
	 * 接受客户端关机信息
	 */
	@ApiOperation("接受客户端关机信息")
	@PostMapping(value = "/saveShutdownStatus")
	public R sleep(@Validated @RequestBody ShutdownStatusDto shutdownStatusDto) {
		
		String deviceId = shutdownStatusDto.getDeviceId();
		String ipAddress = shutdownStatusDto.getIpAddress();
		if (StringUtils.isBlank(deviceId)) {
			return R.fail("自编设备编号不能为空。" + deviceId);
		}
//		if (StringUtils.isBlank(ipAddress)) {
//			return R.fail("ip地址不能为空。" + ipAddress);
//		}
		
		//业务逻辑
		DvDeployment dvDeployment = dvDeploymentService.getByDeviceId(deviceId);
		if (null == dvDeployment) {
			return R
					.fail("找不到该设备。"+ deviceId);
		}else{
            dvDeployment.setDeviceStatus("5");
            dvDeploymentService.updateDvDeployment(dvDeployment);            
		}
		

		R r = R.ok();
		return r;
		
	}
	
}
